package com.zhida.smartcontrol.dialog.kzqlistdialog;

import android.app.Dialog;
import android.os.Bundle;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.jay.tools.recycler.OnItemClick;
import com.zhida.smartcontrol.R;
import com.zhida.smartcontrol.common.bean.LampBean;
import com.zhida.smartcontrol.dialog.grouplistdialog.GroupListAdapter;
import com.zhida.smartcontrol.dialog.grouplistdialog.GroupListDialogContract;
import com.zhida.smartcontrol.dialog.grouplistdialog.GroupListDialogFragment;
import com.zhida.smartcontrol.dialog.grouplistdialog.GroupListDialogPresenter;
import com.zhida.smartcontrol.mvp.MVPBaseDialogFragment;
import com.zhida.smartcontrol.pagectrl.projectdetail.GroupBean;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class KzqListDialogFragment extends MVPBaseDialogFragment<KzqListDialogContract.View, KzqListDialogPresenter> implements KzqListDialogContract.View{
    @BindView(R.id.recycler_view)
    RecyclerView mRView;

    private KzqListAdapter mAdapter;
    private LampBean mBean;
    public static KzqListDialogFragment newInstance(String projectId) {
        Bundle args = new Bundle();
        args.putString("id", projectId);
        KzqListDialogFragment fragment = new KzqListDialogFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected Object getLayout() {
        mShowBottom = true;
        return R.layout.dialog_common_sel;
    }

    @Override
    protected void initDatas(Bundle savedInstanceState) {
        mRView.setLayoutManager(new LinearLayoutManager(mActivity));
        mAdapter = new KzqListAdapter(null);
        mAdapter.bindToRecyclerView(mRView);

        mPresenter.requestKzqList(getArguments().getString("id"),false);
    }

    @OnClick({R.id.btn_cancel, R.id.btn_confirm})
    public void click(View v) {
        switch (v.getId()) {
            case R.id.btn_cancel:
                dismiss();
                break;
            case R.id.btn_confirm:
                if (null != mListener) {
                    mListener.onDestroy(mBean, false);
                    dismiss();
                }
                break;
        }
    }

    @Override
    protected void initEvents(Dialog dialog) {
        mAdapter.setClickListener(new OnItemClick<LampBean>() {
            @Override
            public void onClick(LampBean info, int tag) {
                mBean = info;
            }
        });
    }

    @Override
    public void showKzq(List<LampBean> groupList) {
        mAdapter.replaceData(groupList);
    }
}
